If-Then-Else operators

Basic Syntax

Usage

There are 2 kinds of If statements, the multi-line If, and the single-line If. Generally, it is better to use the multi-line If since it results in clearer formulas.

Multi-line If statements

If x Then

    statementsA

End If

If x is True then evaluate stamentsA.

If x Then

    statementsA

Else

    statementB

End If

If x is True then evaluate statementsA otherwise evaluate statementsB.

If x Then

    statementsA

ElseIf y Then

    statementsB

Else

    statementsC

End If

If x is True then evaluate statementsA; otherwise if y is True, evaluate statementsB; otherwise evaluate statementsC.

Note:    

Single-line If statements

If x Then y Else z

If x is true then do y. If x is not true (Else), do z.

Examples

The following example is applicable to Basic syntax:

If {Employee.Dept} = "Sales" Then

    formula = {Employee.Salary} * 0.06

Else

    formula = {Employee.Salary} * 0.04

End If

Assigns rate of salary increase based on an employee's department

Comments

The If part of the expression can include text, numbers, (Cust#<"10000"), and formulas ({@Formula}), where @Formula is Boolean.

Related topics

For full details on how to use the If statement, see:

If statements (Basic syntax)

Single-line and multi-line If statements (Basic syntax)

Crystal Syntax

Usage

If x Then y Else z

If x is true then do y. If x is not true (Else), do z.

Examples

The following example is applicable to Crystal syntax:

If {customer.POSTAL CODE} <= "49999" Then

    "Blue Label"

Else

    "Ground"

Assigns method of shipping based on distance from ship point.

If ToNumber ({file.ITEM}) >= 2500 and ToNumber({file.ITEM}) < 2600 Then

    "Seasonal"

Else

    ""

If statement includes an and operator for the ToNumber (numeric), ToNumber (string), ToNumber (Boolean) function.

If {file.COUNT} >= 25 Then

    {file.DISTRIBUTOR} * {file.COUNT}

Else

    {file.DEALER} * {file.COUNT}

Quantity ordered determines price list used.

If {file.ONHAND}>10 Then

    {file.ORDERED}

Else

    If {file.ORDERED} < 5 Then

        {file.ORDERED}

    Else

        2

Allocation based on quantity ordered using If-Then-Else nesting.

If PageNumber = 1 Then

    PrintDate

Else

    CDate(0,0,0)

Prints the print date (from the PrintDate function) on the first page, and prints nothing [as designated by the empty date CDate(0,0,0)] on the remaining pages.

Comments
Related topics

For full details on how to use the If statement, see:

If expressions (Crystal syntax)

More details on If expressions (Crystal syntax)

Most formula examples use this operator. Select the formula of interest from the Formulas in action index.



Seagate Software IMG Holdings, Inc.
http://www.seagatesoftware.com
Support services:
http://support.seagatesoftware.com